
const io = require("socket.io-client");

// const uid = 8088636471;
const uid = 7707956447;
const socket = io("wss://test-back.chickentap.com", {
	transports: ["websocket"],
	query: {
		user_id: uid
	},
});

socket.on("connect", function () {
	console.log(`连接成功 socket.connected`)

	const engine = socket.io.engine;
	console.log(engine.transport.name); // in most cases, prints "polling"

	engine.once("upgrade", () => {
		// called when the transport is upgraded (i.e. from HTTP long-polling to WebSocket)
		console.log(engine.transport.name); // in most cases, prints "websocket"
	});

	engine.on("packet", ({ type, data }) => {
		// called for each packet received
		console.log(`packet type:${type},data:${data}`)
	});

	engine.on("packetCreate", ({ type, data }) => {
		// called for each packet sent
	});

	engine.on("drain", () => {
		// called when the write buffer is drained
	});

	engine.on("close", (reason) => {
		// called when the underlying connection is closed
		console.log(`engine close reason:${reason}`)
	});
	socket.emit("unsubscribeLiteSync")
	socket.emit("getTasks")
	socket.emit("getBusinessesToBuy", uid)
	socket.emit("subscribeLiteSync", uid)
	setInterval(function () {
		console.log(JSON.stringify({
			user_id: uid,
			position: {
				x: 296.79315185546875,
				y: 309.07708740234375
			},
			time_stamp: (new Date()).getTime()
		}))
		socket.emit("clickEvent", JSON.stringify({
			user_id: uid,
			position: {
				x: 296.79315185546875,
				y: 309.07708740234375
			},
			time_stamp: (new Date()).getTime()
		}))
	}, 10)
	// socket.emit(5)
})

socket.on("disconnect", () => {
	console.log(`socket disconnect ${socket.id}`);
});

// npm install socket.io-client

